/*
 * @Author: szx
 * @Date: 2021-11-13 11:37:35
 * @LastEditTime: 2021-11-13 13:27:46
 * @Description:
 * @FilePath: \leetcode\500-599\547\547.js
 */
/**
 * @param {number[][]} isConnected
 * @return {number}
 */
var findCircleNum = function (isConnected) {
    const visited = new Set();
    const queue = new Array();
    const len = isConnected.length;
    let cnt = 0;
    for (let i = 0; i < len; i++) {
        if (!visited.has(i)) {
            queue.push(i);
            cnt++;
            while (queue.length) {
                const j = queue.shift();
                visited.add(j);
                for (let k = 0; k < len; k++) {
                    if (isConnected[j][k] === 1 && !visited.has(k)) {
                        queue.push(k);
                    }
                }
            }
        }
    }
    return cnt;
};
